// $Id: xpcom.hpp 2 2009-09-02 08:47:42Z joseph2002 $
/*
 * Copyright 2008-2009 Joseph Wu
 * Distributed under the Boost Software License, Version 1.0.
 * (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
 *
 * For more information, see http://xpcomplus.sourceforge.net
 */

#ifndef XPCOM_API_XPCOM_HPP
#define XPCOM_API_XPCOM_HPP

#include "config.hpp"
#include <xpcom/types.hpp>

#ifdef XPCOM_USE_INTERNAL_API
# define NS_InitXPCOM2               NS_InitXPCOM2_P
# define NS_InitXPCOM3               NS_InitXPCOM3_P
# define NS_ShutdownXPCOM            NS_ShutdownXPCOM_P
# define NS_GetServiceManager        NS_GetServiceManager_P
# define NS_GetComponentManager      NS_GetComponentManager_P
# define NS_GetComponentRegistrar    NS_GetComponentRegistrar_P
# define NS_GetMemoryManager         NS_GetMemoryManager_P
# define NS_NewLocalFile             NS_NewLocalFile_P
# define NS_NewNativeLocalFile       NS_NewNativeLocalFile_P
# define NS_GetDebug                 NS_GetDebug_P
# define NS_GetTraceRefcnt           NS_GetTraceRefcnt_P
# define NS_Alloc                    NS_Alloc_P
# define NS_Realloc                  NS_Realloc_P
# define NS_Free                     NS_Free_P
# define NS_DebugBreak               NS_DebugBreak_P
# define NS_LogInit                  NS_LogInit_P
# define NS_LogTerm                  NS_LogTerm_P
# define NS_LogAddRef                NS_LogAddRef_P
# define NS_LogRelease               NS_LogRelease_P
# define NS_LogCtor                  NS_LogCtor_P
# define NS_LogDtor                  NS_LogDtor_P
# define NS_LogCOMPtrAddRef          NS_LogCOMPtrAddRef_P
# define NS_LogCOMPtrRelease         NS_LogCOMPtrRelease_P
# define NS_CycleCollectorSuspect    NS_CycleCollectorSuspect_P
# define NS_CycleCollectorForget     NS_CycleCollectorForget_P
# define NS_CycleCollectorSuspect2   NS_CycleCollectorSuspect2_P
# define NS_CycleCollectorForget2    NS_CycleCollectorForget2_P
#endif // XPCOM_USE_INTERNAL_API

class nsIModule;
class nsIComponentManager;
class nsIComponentRegistrar;
class nsIServiceManager;
class nsIFile;
class nsILocalFile;
class nsIDirectoryServiceProvider;
class nsIMemory;
class nsIDebug;
class nsITraceRefcnt;
#if XPCOM_API_VERSION >= XPCOM_API_VERSION_1_9_1
struct nsPurpleBufferEntry;
#endif // XPCOM_API_VERSION >= XPCOM_API_VERSION_1_9_1

_XPCOM_API(xpcom::result_t)
NS_InitXPCOM2(
        nsIServiceManager** result,
        nsIFile* binDirectory,
        nsIDirectoryServiceProvider* appFileLocationProvider);

#if XPCOM_API_VERSION >= XPCOM_API_VERSION_1_8
typedef xpcom::result_t
(_NSPR_CALLBACK *nsGetModuleProc)(
        nsIComponentManager* aCompMgr,
        nsIFile* location,
        nsIModule** return_cobj);

typedef struct nsStaticModuleInfo {
  const char*       name;
  nsGetModuleProc   getModule;
} nsStaticModuleInfo;

_XPCOM_API(xpcom::result_t)
NS_InitXPCOM3(
        nsIServiceManager** result,
        nsIFile* binDirectory,
        nsIDirectoryServiceProvider* appFileLocationProvider,
        const nsStaticModuleInfo* staticComponents,
        xpcom::uint32_t componentCount);
#endif // XPCOM_API_VERSION >= XPCOM_API_VERSION_1_8

_XPCOM_API(xpcom::result_t)
NS_ShutdownXPCOM(nsIServiceManager* servMgr);


_XPCOM_API(xpcom::result_t)
NS_GetServiceManager(nsIServiceManager** result);

_XPCOM_API(xpcom::result_t)
NS_GetComponentManager(nsIComponentManager** result);

_XPCOM_API(xpcom::result_t)
NS_GetComponentRegistrar(nsIComponentRegistrar** result);

_XPCOM_API(xpcom::result_t)
NS_GetMemoryManager(nsIMemory** result);

_XPCOM_API(xpcom::result_t)
NS_GetDebug(nsIDebug** result);

_XPCOM_API(xpcom::result_t)
NS_GetTraceRefcnt(nsITraceRefcnt** result);

#ifdef __cplusplus
_XPCOM_API(xpcom::result_t)
NS_NewLocalFile(
        const xpcom::wstring& path,
        xpcom::bool_t followLinks,
        nsILocalFile** result);

_XPCOM_API(xpcom::result_t)
NS_NewNativeLocalFile(
        const xpcom::string& path,
        xpcom::bool_t followLinks,
        nsILocalFile** result);
#endif

#if XPCOM_API_VERSION >= XPCOM_API_VERSION_1_8
_XPCOM_API(void*)
NS_Alloc(xpcom::size_t size);

_XPCOM_API(void*)
NS_Realloc(void* ptr, xpcom::size_t size);

_XPCOM_API(void)
NS_Free(void* ptr);
#endif // XPCOM_API_VERSION >= XPCOM_API_VERSION_1_8

#if XPCOM_API_VERSION >= XPCOM_API_VERSION_1_9
enum
{
    NS_DEBUG_WARNING = 0,
    NS_DEBUG_ASSERTION = 1,
    NS_DEBUG_BREAK = 2,
    NS_DEBUG_ABORT = 3
};

_XPCOM_API(void)
NS_DebugBreak(
        xpcom::uint32_t aSeverity,
        const char* aStr, const char* aExpr,
        const char* aFile, xpcom::int32_t aLine);

_XPCOM_API(void)
NS_LogInit();

_XPCOM_API(void)
NS_LogTerm();

_XPCOM_API(void)
NS_LogCtor(void* aPtr, const char* aTypeName, xpcom::uint32_t aInstanceSize);

_XPCOM_API(void)
NS_LogDtor(void* aPtr, const char* aTypeName, xpcom::uint32_t aInstanceSize);

_XPCOM_API(void)
NS_LogAddRef(
        void* aPtr,
        xpcom::refcnt_t aNewRefCnt,
        const char* aTypeName,
        xpcom::uint32_t aInstanceSize);

_XPCOM_API(void)
NS_LogRelease(
        void* aPtr,
        xpcom::refcnt_t aNewRefCnt,
        const char* aTypeName);

_XPCOM_API(void)
NS_LogCOMPtrAddRef(void* aCOMPtr, xpcom::interface* aObject);

_XPCOM_API(void)
NS_LogCOMPtrRelease(void* aCOMPtr, xpcom::interface* aObject);

_XPCOM_API(xpcom::bool_t)
NS_CycleCollectorSuspect(xpcom::interface* n);

_XPCOM_API(xpcom::bool_t)
NS_CycleCollectorForget(xpcom::interface* n);
#endif // XPCOM_API_VERSION >= XPCOM_API_VERSION_1_9

#if XPCOM_API_VERSION >= XPCOM_API_VERSION_1_9_1
_XPCOM_API(nsPurpleBufferEntry*)
NS_CycleCollectorSuspect2(xpcom::interface* n);

_XPCOM_API(xpcom::bool_t)
NS_CycleCollectorForget2(nsPurpleBufferEntry* e);
#endif // XPCOM_API_VERSION >= XPCOM_API_VERSION_1_9_1

// Categories (in the category manager service) used by XPCOM:
#if XPCOM_API_VERSION >= XPCOM_API_VERSION_1_8
#define NS_XPCOM_DIRECTORY_PROVIDER_CATEGORY "xpcom-directory-providers"
#define NS_XPCOM_STARTUP_CATEGORY "xpcom-startup"
#define NS_XPCOM_STARTUP_OBSERVER_ID "xpcom-startup"
#define NS_XPCOM_SHUTDOWN_OBSERVER_ID "xpcom-shutdown"
#define NS_XPCOM_CATEGORY_ENTRY_ADDED_OBSERVER_ID "xpcom-category-entry-added"
#define NS_XPCOM_CATEGORY_ENTRY_REMOVED_OBSERVER_ID "xpcom-category-entry-removed"
#define NS_XPCOM_CATEGORY_CLEARED_OBSERVER_ID "xpcom-category-cleared"
#endif // XPCOM_API_VERSION >= XPCOM_API_VERSION_1_8

#endif // XPCOM_API_XPCOM_HPP
